package cn.tedu.egmvc8.controller;

import cn.tedu.egmvc8.mapper.NoticeMapper;
import cn.tedu.egmvc8.pojo.dto.NoticeAddParam;
import cn.tedu.egmvc8.pojo.dto.NoticeAddQuery;
import cn.tedu.egmvc8.pojo.entity.Notice;
import cn.tedu.egmvc8.pojo.vo.NoticeDetailInfoVO;
import cn.tedu.egmvc8.pojo.vo.NoticeListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @RequestMapping("/v1/notice/add")
    @ResponseBody
    public String add(NoticeAddParam noticeAddParam){
        System.out.println("noticeController="+noticeAddParam);
        Notice notice=new Notice();
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setUserId(100L);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        noticeMapper.insertNotice(notice);
        return "新增资讯成功";
    }
    @GetMapping("/v1/notice/list")
    @ResponseBody
    public List<NoticeListVO> list(NoticeAddQuery noticeAddQuery){
        System.out.println("noticeController="+noticeAddQuery);
        List<NoticeListVO> noticeListVOs = noticeMapper.list(noticeAddQuery);
        return noticeListVOs;
    }
    @GetMapping("/v1/notice/detail")
    @ResponseBody
    public List<NoticeDetailInfoVO> detail(NoticeAddQuery noticeAddQuery){
        System.out.println("noticeController="+noticeAddQuery);
        List <NoticeDetailInfoVO> noticeDetailInfoVOs = noticeMapper.detail(noticeAddQuery);
        return noticeDetailInfoVOs;
    }
}
